﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
using System.Collections.Generic;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class VABKOPF
    {
        VABKOPF APK;
        public readonly static VABKOPF Instance = new VABKOPF();
        public string NEWABK(Dictionary<string, object> pm)
        {
            RUNID = (string)pm["RUNID"];
            dwData = TBMain.NewRow();
            KRS = (string)pm["KRS"];
            SetUpNewRow(ref dwData, null);
            dwData["ABKAUFART"] = (string)pm["AUFART"];
            dwData["ABKAUFKRS"] = KRS;
            if(pm.ContainsKey("LFD"))
            {
                LFD= (string)pm["LFD"];
            }
            else
            {
                LFD = VSDDAT.SD22.GETNEXT("0022", KRS, "ABKOPF");
            }           
            dwData["ABKAUFLFD"] = Helpers.Helper.Right("000000" + LFD, 6);
            dwData["ABKAEDAT"] = date; ;
            dwData["ABKKDAUFTNR"] = ((string)pm["ORDERNUM"]).PadRight(20);
            //dwData["ABKARTSB"] = app.User;
            dwData["ABKKDAUFDAT"] = date;
            bool IsReload = true;
            if (pm.ContainsKey("RELOADABK"))
            {
                IsReload = (bool)pm["RELOADABK"];
            }
            SResult = QABK01(dwData);
            if (SResult.Tables[0].Rows.Count > 0)
                return KRS + LFD;
            Insert(dwData, IsReload);
            return KRS + LFD;
        }
        public void LOAD(Dictionary<string, object> pm)
        {

            dwData = TBMain.NewRow();
            RUNID = (string)pm["RUNID"];
            KRS = (string)pm["KRS"];
            LFD = (string)pm["LFD"];

            SetUpNewRow(ref dwData, null);
            dwData["ABKAUFART"] = (string)pm["AUFART"];
            dwData["ABKAUFKRS"] = KRS;
            dwData["ABKAUFLFD"] = Helpers.Helper.Right("000000" + LFD, 6);
            dwData["ABKAEDAT"] = date; ;
            dwData["ABKKDAUFTNR"] = ((string)pm["ORDERNUM"]).PadRight(20);
            //'dwData["ABKARTSB"] = app.User;
            dwData["ABKKDAUFDAT"] = date;
            SResult = QABK01(dwData);           
            if (SResult.Tables[0].Rows.Count > 0)
            {
                MergeData(SResult);
                return;
            }                
            Insert(dwData, false);
        }
        public void Insert(DataRow _dwABK, bool IsReload = true)
        {
            InsertABKOPF(_dwABK, app.company);
            TBMain.Rows.InsertAt(_dwABK, 0);
            if (IsReload)
            {
                RELOADABK(_dwABK);
            }
        }
        public void RELOADABK(DataRow _dwABK)
        {
            MessageInfo msg = new MessageInfo();
            msg.MSGTYPE = "RELOADABK";
            msg.Sender = RUNID;
            msg.ACTION = "RELOADABK";
            msg.ORDER = _dwABK["ABKAUFKRS"].ToString() + _dwABK["ABKAUFLFD"].ToString();
            msg.Where = app.User;
            VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
        }
    }
    public partial class VABKOPF
    {
        public string ABKAUFKRS { get { if (dwMaster == null) return ""; return dwMaster["ABKAUFKRS"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAUFKRS"] = value; OnPropertyChanged("ABKAUFKRS", value); } } //lENGth 2
        public string ABKAUFLFD { get { if (dwMaster == null) return ""; return dwMaster["ABKAUFLFD"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAUFLFD"] = value; OnPropertyChanged("ABKAUFLFD", value); } } //lENGth 6
        public string ABKAUFART { get { if (dwMaster == null) return ""; return dwMaster["ABKAUFART"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAUFART"] = value; OnPropertyChanged("ABKAUFART", value); } } //lENGth 2

        #region======ColumnSchema==========
        /*
                 public string ABKMANDANT { get { if (dwMaster == null) return ""; return dwMaster["ABKMANDANT"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKMANDANT"] = value; OnPropertyChanged("ABKMANDANT", value); } } //lENGth 2
                 public string ABKKUNDNR { get { if (dwMaster == null) return ""; return dwMaster["ABKKUNDNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKKUNDNR"] = value; OnPropertyChanged("ABKKUNDNR", value); } } //lENGth 8
                 public string ABKWERK { get { if (dwMaster == null) return ""; return dwMaster["ABKWERK"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKWERK"] = value; OnPropertyChanged("ABKWERK", value); } } //lENGth 3
                 public string ABKABT { get { if (dwMaster == null) return ""; return dwMaster["ABKABT"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKABT"] = value; OnPropertyChanged("ABKABT", value); } } //lENGth 3
                 public string ABKVTRNR { get { if (dwMaster == null) return ""; return dwMaster["ABKVTRNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKVTRNR"] = value; OnPropertyChanged("ABKVTRNR", value); } } //lENGth 8
                 public double ABKAEDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKAEDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKAEDAT"] = value; OnPropertyChanged("ABKAEDAT", value); } } //lENGth 0
                 public string ABKKDAUFTNR { get { if (dwMaster == null) return ""; return dwMaster["ABKKDAUFTNR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKKDAUFTNR"] = value; OnPropertyChanged("ABKKDAUFTNR", value); } } //lENGth 20
                 public double ABKKDAUFDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKKDAUFDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKKDAUFDAT"] = value; OnPropertyChanged("ABKKDAUFDAT", value); } } //lENGth 0
                 public string ABKKDZEICH { get { if (dwMaster == null) return ""; return dwMaster["ABKKDZEICH"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKKDZEICH"] = value; OnPropertyChanged("ABKKDZEICH", value); } } //lENGth 15
                 public string ABKKDSB { get { if (dwMaster == null) return ""; return dwMaster["ABKKDSB"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKKDSB"] = value; OnPropertyChanged("ABKKDSB", value); } } //lENGth 8
                 public string ABKARTSB { get { if (dwMaster == null) return ""; return dwMaster["ABKARTSB"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKARTSB"] = value; OnPropertyChanged("ABKARTSB", value); } } //lENGth 8
                 public string ABKORDER { get { if (dwMaster == null) return ""; return dwMaster["ABKORDER"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKORDER"] = value; OnPropertyChanged("ABKORDER", value); } } //lENGth 4
                 public string ABKSPED { get { if (dwMaster == null) return ""; return dwMaster["ABKSPED"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKSPED"] = value; OnPropertyChanged("ABKSPED", value); } } //lENGth 3
                 public string ABKVERSART { get { if (dwMaster == null) return ""; return dwMaster["ABKVERSART"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKVERSART"] = value; OnPropertyChanged("ABKVERSART", value); } } //lENGth 3
                 public string ABKVERPART { get { if (dwMaster == null) return ""; return dwMaster["ABKVERPART"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKVERPART"] = value; OnPropertyChanged("ABKVERPART", value); } } //lENGth 3
                 public string ABKVERSADR { get { if (dwMaster == null) return ""; return dwMaster["ABKVERSADR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKVERSADR"] = value; OnPropertyChanged("ABKVERSADR", value); } } //lENGth 8
                 public string ABKDIVADR { get { if (dwMaster == null) return ""; return dwMaster["ABKDIVADR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKDIVADR"] = value; OnPropertyChanged("ABKDIVADR", value); } } //lENGth 8
                 public string ABKBSTADR { get { if (dwMaster == null) return ""; return dwMaster["ABKBSTADR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKBSTADR"] = value; OnPropertyChanged("ABKBSTADR", value); } } //lENGth 8
                 public double ABKBSTDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKBSTDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKBSTDAT"] = value; OnPropertyChanged("ABKBSTDAT", value); } } //lENGth 0
                 public string ABKRECHADR { get { if (dwMaster == null) return ""; return dwMaster["ABKRECHADR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKRECHADR"] = value; OnPropertyChanged("ABKRECHADR", value); } } //lENGth 8
                 public string ABKAUFTTXT1 { get { if (dwMaster == null) return ""; return dwMaster["ABKAUFTTXT1"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAUFTTXT1"] = value; OnPropertyChanged("ABKAUFTTXT1", value); } } //lENGth 64
                 public string ABKAUFTTXT2 { get { if (dwMaster == null) return ""; return dwMaster["ABKAUFTTXT2"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAUFTTXT2"] = value; OnPropertyChanged("ABKAUFTTXT2", value); } } //lENGth 64
                 public string ABKZENTREG { get { if (dwMaster == null) return ""; return dwMaster["ABKZENTREG"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKZENTREG"] = value; OnPropertyChanged("ABKZENTREG", value); } } //lENGth 1
                 public string ABKTEXTE11 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE11"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE11"] = value; OnPropertyChanged("ABKTEXTE11", value); } } //lENGth 2
                 public string ABKTEXTE12 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE12"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE12"] = value; OnPropertyChanged("ABKTEXTE12", value); } } //lENGth 2
                 public string ABKTEXTE13 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE13"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE13"] = value; OnPropertyChanged("ABKTEXTE13", value); } } //lENGth 2
                 public string ABKTEXTE14 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE14"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE14"] = value; OnPropertyChanged("ABKTEXTE14", value); } } //lENGth 2
                 public string ABKTEXTE21 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE21"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE21"] = value; OnPropertyChanged("ABKTEXTE21", value); } } //lENGth 2
                 public string ABKTEXTE22 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE22"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE22"] = value; OnPropertyChanged("ABKTEXTE22", value); } } //lENGth 2
                 public string ABKTEXTE23 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE23"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE23"] = value; OnPropertyChanged("ABKTEXTE23", value); } } //lENGth 2
                 public string ABKTEXTE24 { get { if (dwMaster == null) return ""; return dwMaster["ABKTEXTE24"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKTEXTE24"] = value; OnPropertyChanged("ABKTEXTE24", value); } } //lENGth 2
                 public double ABKAENDZL { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKAENDZL"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKAENDZL"] = value; OnPropertyChanged("ABKAENDZL", value); } } //lENGth 0
                 public string ABKAENDBEN { get { if (dwMaster == null) return ""; return dwMaster["ABKAENDBEN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAENDBEN"] = value; OnPropertyChanged("ABKAENDBEN", value); } } //lENGth 8
                 public double ABKAENDDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKAENDDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKAENDDAT"] = value; OnPropertyChanged("ABKAENDDAT", value); } } //lENGth 0
                 public string ABKNEUBEN { get { if (dwMaster == null) return ""; return dwMaster["ABKNEUBEN"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKNEUBEN"] = value; OnPropertyChanged("ABKNEUBEN", value); } } //lENGth 8
                 public double ABKNEUDAT { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKNEUDAT"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKNEUDAT"] = value; OnPropertyChanged("ABKNEUDAT", value); } } //lENGth 0
                 public string ABKDIVARTKZ { get { if (dwMaster == null) return ""; return dwMaster["ABKDIVARTKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKDIVARTKZ"] = value; OnPropertyChanged("ABKDIVARTKZ", value); } } //lENGth 1
                 public string ABKAGKKZ { get { if (dwMaster == null) return ""; return dwMaster["ABKAGKKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKAGKKZ"] = value; OnPropertyChanged("ABKAGKKZ", value); } } //lENGth 1
                 public string ABKKDKONTR { get { if (dwMaster == null) return ""; return dwMaster["ABKKDKONTR"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKKDKONTR"] = value; OnPropertyChanged("ABKKDKONTR", value); } } //lENGth 15
                 public double ABKSTKZL { get { if (dwMaster == null) return 0.0; return  Convert.ToDouble(dwMaster["ABKSTKZL"].ToString()); } set { if (dwMaster == null) return; dwMaster["ABKSTKZL"] = value; OnPropertyChanged("ABKSTKZL", value); } } //lENGth 0
                 public string ABKCOMPKZ { get { if (dwMaster == null) return ""; return dwMaster["ABKCOMPKZ"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKCOMPKZ"] = value; OnPropertyChanged("ABKCOMPKZ", value); } } //lENGth 1
                 public string ABKFILLER { get { if (dwMaster == null) return ""; return dwMaster["ABKFILLER"].ToString(); } set { if (dwMaster == null) return; dwMaster["ABKFILLER"] = value; OnPropertyChanged("ABKFILLER", value); } } //lENGth 71
        */
        #endregion
    }
}
